const app = getApp();
Page({
  data: {

  },
  onLoad: function (options) {
    let self = this;
    wx.getStorage({
      key: 'key',
      success: res => {
        self.setData({
          key: res.data
        })
        self.getUserName()
      }
    })
  },
  getUserName: function () {
    let self = this;
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=member_nick_name&op=get_nick_name',
      data: {
        key: self.data.key
      },
      method: 'GET',
      success: res => {
        if (res.data.code == 200) {
          self.setData({
            member_nickname: res.data.datas.member_Nickname,
            inputName: res.data.datas.member_Nickname
          })
        }
      }
    })
  },
  inputName: function (e) {
    this.setData({
      inputName: e.detail.value
    })
  },
  submitName: function () {
    let self = this;
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=member_nick_name&op=saveNickNameApp',
      data: {
        key: self.data.key,
        nickname: self.data.inputName,
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        if (res.data.code == 200) {
          wx.showToast({
            title: '修改成功！',
            icon: 'none'
          })
          setTimeout(() => {
            wx.switchTab({
              url: '../member/member'
            })
          }, 1000);
        } else {
          wx.showToast({
            title: res.data.datas.error,
            icon: 'none'
          })
        }
      }
    })
  }
})